home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_018 / mc68010 / chop.c < prev    next >
Text File  |  1992-05-06  |  2KB  |  78 lines

  1. /*******************************************
  2.  *  Chop                                   *
  3.  *                                         *
  4.  *  by J S Plegge                          *
  5.  *                                         *
  6.  *  Truncate files to specified length     *
  7.  *                                         *
  8.  *  USAGE:  Chop <input> <output> <size>   *
  9.  *                                         *
  10.  *******************************************/
  11.  
  12. #include <stdio.h>
  13. #include <ctype.h>
  14.  
  15. usage()
  16. {
  17. puts("Usage:  CHOP <input> <output> <size>");
  18. }
  19.  
  20. main(argc, argv)
  21.  
  22. int argc;
  23. char *argv[];
  24.  
  25. {
  26. int i;
  27. int c;
  28. FILE *in, *out;
  29. long int l;
  30.  
  31. if (argc < 4)
  32.    {
  33.    puts("Bad arguments.");
  34.    usage();
  35.    exit(20);
  36.    }
  37.  
  38. l=atol(argv[3]);
  39.  
  40. if (l <= 0)
  41.    {
  42.    puts("Invalid size.");
  43.    usage();
  44.    exit(20);
  45.    }
  46.  
  47. if ((in = fopen (argv[1], "r")) == 0)
  48.    {
  49.    printf("Can't open %s\n", argv[1]);
  50.    exit(20);
  51.    }
  52.  
  53. if ((out = fopen (argv[2], "w")) == 0)
  54.    {
  55.    printf("Can't open %s\n", argv[2]);
  56.    exit(20);
  57.    }
  58.  
  59. printf("Writing %d bytes from %s to %s \n",l,argv[1],argv[2]);
  60.  
  61. i=0;
  62.  
  63. while (((c = getc(in)) !=EOF) && (i < l))
  64.   {
  65.   i=i+1;
  66.   putc(c, out);
  67.   }                     /*  endwhile  */
  68.  
  69. if (i == l)
  70.    puts("Done!");
  71. else
  72.    puts("CHOP ended at EOF on input.");
  73.  
  74. fclose (in);
  75. fclose (out);
  76.  
  77. }                    /* end of program  */
  78.